package com.alipay.app.groupmeal.standard.widget.business;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.alipay.app.groupmeal.standard.R;
import com.alipay.app.groupmeal.standard.constant.ConfigConstant;
import com.alipay.app.groupmeal.standard.constant.SystemConsts;
import com.alipay.app.groupmeal.standard.event.TimeEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ProjectName: 团餐
 * @ClassName: StatusBar
 * @Description: 状态栏
 * @Author: bd-001935
 * @CreateDate: 4/17/22 8:26 PM
 * @UpdateUser: bd-001935
 * @UpdateDate: 4/17/22 8:26 PM
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class StatusBar extends BaseBScreenView {


    private TextView posnumTv;
    private TextView timeTv;

    public StatusBar(Context context) {
        this(context, null);
    }

    public StatusBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StatusBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.view_status_bar;
    }

    @Override
    protected void initView(View view) {
        posnumTv = findViewById(R.id.posnumTv);
        timeTv = findViewById(R.id.timeTv);
        if (!EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().register(this);
    }

    @Override
    protected void initData() {
        posnumTv.setText(SystemConsts.getSystemConsts().getPosnum());
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTimesSet(TimeEvent timeEvent) {

        if (ConfigConstant.onOffLine) {
            timeTv.setText(new SimpleDateFormat("HH:mm").format(new Date()));
        } else {
            timeTv.setText("脱机消费  " + new SimpleDateFormat("HH:mm").format(new Date()));
        }

        posnumTv.setText(SystemConsts.getSystemConsts().getPosnum());
    }

}
